package disk_rpc

import (
	"disk/disk_rpc_server/disk_pb"
	"disk/service/disk_rpc/service"
	"disk/utils/etcd"
	"fmt"
	"github.com/spf13/viper"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
)

func NewClient() disk_pb.DiskServiceClient {
	addr := etcd.GetAddrFromEtcd(viper.GetString("etcd.keys.disk_rpc"), service.ETCD)
	conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Println(fmt.Sprintf("grpc connect addr [%s] 连接失败 %s", addr, err))
	}
	client := disk_pb.NewDiskServiceClient(conn)
	return client
}
